package Gui;

import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;

import client.ClientHendler;
import client.LibaryMain;

import Control.*;
import Logic.LoginInfo;
import javax.swing.ImageIcon;

/**
 * this class  implements gui of remove book 
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class RemoveBook extends JPanel{
	/**
	 * 
	 */
	private static final long serialVersionUID = -1780380478724563374L;
	private static JTextField idtextField;
	public static JTextField showid;
	public static JTextField showtitle;
	public int i;
	

	/**
	 * function that removes book 
	 */
	
	RemoveBook(){
		setBackground(new Color(153, 204, 255));
		
		JLabel lblRmoveBook = new JLabel("Remove a Book");
		lblRmoveBook.setBounds(149, 26, 278, 32);
		lblRmoveBook.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 26));
		
		JLabel lblEnterBookId = new JLabel("Enter Book Id");
		lblEnterBookId.setBounds(172, 238, 112, 20);
		lblEnterBookId.setFont(new Font("Tahoma", Font.BOLD, 16));
		
		idtextField = new JTextField();
		idtextField.setBounds(409, 235, 205, 28);
		idtextField.setFont(new Font("Tahoma", Font.BOLD, 14));
		idtextField.setColumns(10);
		//handel back button
		JButton btnBack = new JButton("Back");
		btnBack.setBounds(44, 629, 65, 25);
		btnBack.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnBack.addActionListener(new java.awt.event.ActionListener() {     
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnback(ev);
            					
			}

			private void btnback(ActionEvent ev) {
				
				MainScreen.cardLayot.show(MainScreen.card,DirectorWindow.roll);
				
			}
        });
		
		
		//handel logout button
		JButton btnLogout = new JButton("Logout");
		btnLogout.setBounds(848, 629, 83, 25);
		btnLogout.setFont(new Font("Tahoma", Font.BOLD, 14));
		
		btnLogout.addActionListener(new java.awt.event.ActionListener() {      
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnLogOut(ev);
            					
			}

			private void btnLogOut(ActionEvent ev) {
				ArrayList<String> Arr=new ArrayList<String>();
				Arr.add("Logout");
				Arr.add("Worker");
				Arr.add(LoginInfo.UserName);
				LibaryMain.chat.handleMessageFromGui(Arr);
				MainScreen.cardLayot.show(MainScreen.card, "Login");
				
			}
        });
		
		JButton btnRemove = new JButton("Remove");
		btnRemove.setBounds(723, 230, 170, 36);
		btnRemove.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnRemove.addActionListener(new java.awt.event.ActionListener() {     
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnRemove(ev);
            					
			}

			public void btnRemove(ActionEvent ev) {
				 String id=idtextField.getText();
				 ArrayList<String> Arr=new ArrayList<String>();
		         Arr.add("GetBook");
		         Arr.add(id);
		         LibaryMain.chat.handleMessageFromGui(Arr);
			
			}
		});
		
		JLabel lblBookId = new JLabel("Book Id");
		lblBookId.setBounds(66, 545, 63, 20);
		lblBookId.setFont(new Font("Tahoma", Font.BOLD, 16));
		
		JLabel lblBookTitle = new JLabel("Book Title");
		lblBookTitle.setBounds(66, 585, 84, 20);
		lblBookTitle.setFont(new Font("Tahoma", Font.BOLD, 16));
		
		showid = new JTextField();
		showid.setBounds(281, 545, 211, 27);
		showid.setColumns(10);
		
		showtitle = new JTextField();
		showtitle.setBounds(281, 587, 468, 27);
		showtitle.setColumns(10);
		setLayout(null);
		add(btnBack);
		add(lblBookTitle);
		add(lblBookId);
		add(btnRemove);
		add(showtitle);
		add(showid);
		add(btnLogout);
		add(lblRmoveBook);
		add(lblEnterBookId);
		add(idtextField);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon(RemoveBook.class.getResource("/Gui/images/recycle-bin-icon-512x512.png")));
		label.setBounds(247, 146, 743, 524);
		add(label);
		
		
		
		
	}
/**
 * update the remove book window
 * @param get the book details 
 */
	public void updatewindow(String[] str1){
		RemoveBook.showid.setText(str1[1]);
		RemoveBook.showtitle.setText((str1[2]));
		RemoveBook.showid.setEditable(false);
		RemoveBook.showtitle.setEditable(false);
		i=JOptionPane.showConfirmDialog(null, "Are You Sure ?");	
		System.out.print(i);
		if(i==1||i==2){
			JOptionPane.showMessageDialog(null, "Check Again The Book ID And Press Remove");
		}
		else if (i==0){
			String id=idtextField.getText();
			 ArrayList<String> Arr=new ArrayList<String>();
	         Arr.add("RemoveBook");
	         Arr.add(id);
	         LibaryMain.chat.handleMessageFromGui(Arr);
		}
		
		
	}

	   
}
